<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>图书管理系统</title>
    <link rel="stylesheet" th:href="@{/css/style.css}" />
</head>
<body>
<div class="container">
    <h1>图书列表</h1>

    <!-- 添加图书表单 -->
    <div class="add-book-form">
        <h2>添加新图书</h2>
        <a th:href="@{/users}">用户主页</a>
        <form th:action="@{/books/add}" th:object="${book}" method="post">
            <div>
                <label for="bookname">书名:</label>
                <input type="text" id="bookname" th:field="*{bookname}" required />
            </div>
            <div>
                <label for="author">作者:</label>
                <input type="text" id="author" th:field="*{author}" required />
            </div>
            <div>
                <input type="submit" value="添加图书" />
            </div>
        </form>
    </div>

    <!-- 图书列表 -->
    <div class="book-list">
        <h2>现有图书</h2>
        <table>
            <thead>
            <tr>
                <th>ID</th>
                <th>书名</th>
                <th>作者</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="book : ${books}">
                <td th:text="${book.id}">ID</td>
                <td th:text="${book.bookname}">书名</td>
                <td th:text="${book.author}">作者</td>
                <td>
                    <a th:href="@{/books/edit/{id}(id=${book.id})}">编辑</a>
                    <a th:href="@{/books/delete/{id}(id=${book.id})}"
                       onclick="return confirm('确定要删除这本书吗?')">删除</a>
                </td>
            </tr>
            <tr th:if="${#lists.isEmpty(books)}">
                <td colspan="4">暂无图书数据</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
